package problem167;

//167. 两数之和 II - 输入有序数组
//https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/?envType=study-plan-v2&envId=top-interview-150

//双指针解法

class Solution {
    public int[] twoSum(int[] numbers, int target) {
        int l = 0, r = numbers.length-1;
        while(l < r) {
            int x = numbers[l] + numbers[r];
            if(x < target) {
                l++;
            }else if(x > target) {
                r--;
            }else {
                return new int[]{l+1, r+1};
            }
        }
        return new int[]{0,0};
    }
}